package com.imooc.mall.util;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;

import java.io.IOException;

/**
 *  图片工具类
 */
public class ImageUtil {

    public static void main(String[] args) throws IOException {
        String path = "D:\\temp\\";
        // 切割
        Thumbnails.of(path + "1.jpg").sourceRegion(Positions.BOTTOM_RIGHT, 50, 50)
                .size(50, 50).toFile(path+"crop.jpg");

        // 缩放
        Thumbnails.of(path+"1.jpg").scale(0.7).toFile(path+"scale1.jpg");
        Thumbnails.of(path+"1.jpg").scale(1.5).toFile(path+"scale2.jpg");
        Thumbnails.of(path+"1.jpg").size(500, 500).keepAspectRatio(false).toFile(path+"size1.jpg");

        // 旋转
        Thumbnails.of(path + "1.jpg").rotate(90).toFile(path + "rotate1.jpg");

    }

}
